package net.aiion.weave.impl.xml;

import java.util.ArrayList;
import java.util.List;

import net.aiion.weave.spi.xml.XmlSink;
import net.aiion.weave.spi.xml.XmlSource;
import net.aiion.weave.spi.xml.events.XmlEvent;

public abstract class AbstractXmlSource implements XmlSource
{
    private final List<XmlSink> xmlSinks;

    private XmlContextImpl xmlContext;

    public AbstractXmlSource() {
        xmlContext = new XmlContextImpl();
        xmlSinks = new ArrayList<>();
    }

    @Override
    public void setProperty(final String aName, final Object aValue) {
        xmlContext.setProperty(aName, aValue);
    }

    @Override
    public void removeProperty(final String aName) {
        xmlContext.removeProperty(aName);
    }

    @Override
    public Object getProperty(final String aName) {
        return xmlContext.getProperty(aName);
    }

    @Override
    public <T> T getProperty(final String aName, final Class<T> aType) {
        return xmlContext.getProperty(aName, aType);
    }

    @Override
    public void addSink(final XmlSink aXmlSink) {
        xmlSinks.add(aXmlSink);
    }

    public void dispatchXmlEvent(final XmlEvent aXmlEvent) {
        xmlContext.setXmlSinks(xmlSinks);
        xmlContext.forwardXmlEvent(aXmlEvent);
    }
}
